package top.zuli.package01.class15;

import org.junit.Test;

import java.sql.Time;
import java.sql.Timestamp;
import java.util.Date;

public class TestDemo2 {
    @Test
    public void DateType(){
        //创建java.util.Date
        Date date = new Date();
        //将java.util.Date转为java.sql.Date,通过java.sql.Date的构造方法实现
        java.sql.Date date2 = new java.sql.Date(date.getTime());
        //java.sql.Date转java.util.Date ，向上转型即可。
        Date date3 = date2;

        //java.util.Date转java.sql.Time
        Time time = new Time(date.getTime());
        //time转java.util.Date
        Date date4 = time;

        //java.util.Date转java.sql.Timestamp
        Timestamp timestamp = new Timestamp(date.getTime());
        // timestamp 转date
        Date date5 = timestamp;
    }
}

/*
public class TestDemo2 {
    @Test
    public void DateType(){
        Date date = new Date();
        java.sql.Date date2 = new java.sql.Date(date.getTime());
        Date date3 = date2;
        Time time = new Time(date.getTime());
        Date date4 = time;
        Timestamp timestamp = new Timestamp(date.getTime());
        Date date5 = timestamp;
    }
}
*/

/*
public class TestDemo2 {
    @Test
    public void DateType(){
        Date date = new Date();
        java.sql.Date date2 = new java.sql.Date(date.getTime());
        Date date3 = date2;
        Time time = new Time(date.getTime());
        Date date4 = time;
        Timestamp timestamp = new Timestamp(date.getTime());
        Date date5 = timestamp;
    }
}
*/

/*
public class TestDemo2 {
    @Test
    public void DateType(){
        Date date = new Date();
        java.sql.Date date2 = new java.sql.Date(date.getTime());
        Date date3 = date2;
        Time time = new Time(date.getTime());
        Date date4 = time;
        Timestamp timestamp = new Timestamp(date.getTime());
        Date date5 = timestamp;
    }
}
*/
